#include <iostream>
#include <string>
#include <cctype>
#include "Chapter6_1.h"
using namespace std;
int main()
{
	//practice_6_3();
	//practice_6_5();
	//practice_6_6();
	//practice_6_7();
	//practice_6_10();
	//practice_6_11();
	//practice_6_17();
	//example_p195();
	//practice_6_21();
	//practice_6_22();
	//practice_6_23();
	practice_6_27();
	return 0;
}
//practice 6_3
int fact(int n)
{
	if(n==1||n==0)
		return 1;
	else
		return n*fact(n-1);
}
//along with practice_6_4
void practice_6_3()
{
	int n;
	cin>>n;
	cout<<fact(n)<<endl;
}
//practice_6_5
int abs(int n)
{
	return (n>0)?n:-n;
} 
void practice_6_5()
{
	cout<<abs(-11)<<endl;
}
//practice_6_6
Tuble func(int init_val)
{
	Tuble tmp{};
	int sum_val=0;
	static int sum=0;
	for(int i=0;i<10;++i)
	{
		sum_val+=(init_val-1);	
		sum+=(init_val-1);
	}
	tmp.t1=sum_val;
	tmp.t2=sum;
	return tmp;
}
void practice_6_6()
{
	Tuble tb{};
	for(int i=0;i<10;i++)
		 tb=func(i);
	cout<<tb.t1<<" "<<tb.t2<<endl;
}
//practice_6_7
size_t count_calls()
{
	static size_t ctr=0;
	return ctr++;
}
void practice_6_7()
{
	for(size_t i=0;i!=10;++i)
		cout<<count_calls()<<" ";
}
//practice_6_10
void swap(int *p1,int* p2)
{
	int temp=*p1;
	*p1=*p2;
	*p2=temp;
}
void practice_6_10()
{
	int a=6,b=5;
	int *ptr1=&a,*ptr2=&b;
	cout<<"before swap,a:"<<a<<" b:"<<b<<endl;
	swap(ptr1,ptr2);
	cout<<"after swap,a:"<<a<<" b:"<<b<<endl;
}
//practice_6_11
void reset(int &p)
{
	p=0;
}
void practice_6_11()
{
	int i=9;
	reset(i);
	cout<<i<<endl;
}
//practice_6_17
void has_upper(const string &s)
{
	for(const auto &c:s)
	{
		if(isupper(c))
		{
			cout<<"has upper"<<endl;
			break;
		}
	}
}
void to_lower(string &s){
	for(auto &c:s)
		c=tolower(c);
}
void practice_6_17()
{
	string s("zzykaUki");
	has_upper(s);
	to_lower(s);
	cout<<s<<endl;
}
//example_p195
void print(int (&arr)[10])
{
	for(auto elem:arr)
		cout<<elem<<endl;
}
void example_p195()
{
	int arr[10]={3,5,9,10,11,12,29,19,33,100};
	print(arr);
}
//practice_6_21
int max(int a,const int *b)
{
	return (a>*b)?a:*b;
}
void practice_6_21()
{
	int a=12;
	int b=43;
	int *p=&b;
	cout<<max(a,p);
}
void swap_p(int *&r1,int *&r2)
{
	int *temp=r1;
	r1=r2;
	r2=temp;
}
void practice_6_22()
{
	int a=6,b=7;
	int *p=&a,*q=&b;
	cout<<"before swap,p=:"<<p<<" q="<<q<<" *p="<<*p<<" *q="<<*q<<endl;
	swap_p(p,q);
	cout<<"after swap,p=:"<<p<<" q="<<q<<" *p="<<*p<<" *q="<<*q<<endl;
}
void print(const int *beg,const int *end)
{
	while(beg!=end)
		cout<<*beg++<<" ";
}
void practice_6_23()
{
	int j[6]={0,1,8,2,9,10};
	print(begin(j),end(j));
}
void sum(int &result,initializer_list<int> li)
{
	for(auto beg=li.begin();beg!=li.end();++beg)
		result+=*beg;
}
void practice_6_27()
{
	int result=0;
	sum(result,{3,4,5});
	cout<<result;
}